﻿using System;

namespace BizElements.TemplateEngine
{
    /// <summary>ID specifying component type.</summary>
    public struct ComponentType
    {
        Guid id;
         
        #region CTor.

        /// <summary>
        /// Initializes a new component type.
        /// </summary>
        /// <param name="id">Unique component type ID.</param>
        public ComponentType(Guid id)
        {
            this.id = id;
        }

        #endregion

        #region Operator overloads.

        /// <summary>Returns true if both components have equal IDs.</summary>
        public static bool operator ==(ComponentType x, ComponentType y)
        {
            return (x.id == y.id);
        }

        /// <summary>Returns true if components have different IDs.</summary>
        public static bool operator !=(ComponentType x, ComponentType y)
        {
            return (x.id != y.id);
        }

        /// <summary>Returns the hash code for this instance.</summary>
        public override int GetHashCode()
        {
            return this.id.GetHashCode();
        }

        /// <summary>Returns true if both components have equal IDs.</summary>
        public override bool Equals(object obj)
        {
            ComponentType? other = obj as ComponentType?;
            if (other == null)
                return false;
            else
                return (this.id == other.Value.id);
        }

        #endregion
    }
}